package entities;
import main.Simulation;


/**
 * Class muscle essentially describes a Spring that has a driving force.
 * @author Paul Dannenberg
 * @author Lance Co Ting Keh
 *
 */
public class Muscle extends Spring {
    private static final double FREQUENCY = 10;
    private double myAmplitude;
    private double myStartLength;
    private double myTime;
    /**
     * @param pointObject - first mass connecting to the start point
     * @param pointObject2 - second mass connecting to the end point
     * @param length - length of the muscle
     * @param kVal - spring constant of the muscle
     * @param amplitude - amplitude of the oscillation
     */
    public Muscle(PointObject pointObject, PointObject pointObject2,
            double length, double kVal, double amplitude) {
        super(pointObject, pointObject2, length, kVal);
        myStartLength = length;
        myAmplitude = amplitude;
    }

    @Override
    public void update(Simulation canvas, double dt) {
        double newLength = varyRestLength(dt);
        setLength(newLength);
        super.update(canvas, dt);
    }

    private double varyRestLength(double dt) {
        myTime += dt;
        return myAmplitude * Math.sin(2 * Math.PI * FREQUENCY * myTime)
                + myStartLength;
    }

}
